package ToYesterday.Day06;


import java.io.*;

public class MergeSort {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader("E:\\Users\\wuxiaoxuan\\IdeaProjects\\Algorithm\\src\\Day04\\num.txt"));
        String str;
        String[] s = new String[30294];
        while ((str = in.readLine()) != null) {
            s = str.split(",|\\[|\\]");
            System.out.println(s.length);
        }
        int[] d =new int[50001];
        for (int i = 1; i < s.length; i++) {
            d[i]=(Integer.parseInt(s[i]));
        }
        margesort(d,0,d.length-1);
        for (int b:d){
            System.out.println(b);
        }
    }

    private static void margesort(int[] a, int i, int length) {
        if (i==length){
            return;
        }
        int mid = (i+length)/2;
        margesort(a,i,mid);
        margesort(a,mid+1,length);
        marge(a,i,mid,length);
    }

    private static void marge(int[] a, int i, int mid, int length) {
        int [] b = new int[length+1];
        for (int t = 0;t<=length;t++){
            b[t] = a[t];
        }
        int temp = mid;
        int mid_p = mid+1;
        int k =i;
        while (i<=temp&&mid_p<=length){
            if (b[i]<b[mid_p]){
                a[k]=b[i];
                k++;
                i++;
            }else {
                a[k]=b[mid_p];
                mid_p++;
                k++;
            }
        }
        while (i<=temp){
            a[k]=b[i];
            i++;
            k++;
        }
        while (mid_p<=length){
            a[k]=b[mid_p];
            k++;
            mid_p++;
        }

    }


}
